using Microsoft.SharePoint;
using ISolutions.WCMTools.Impl;

namespace ISolutions.WCMTools.FeatureReceiver
{
   public class PageVariationFeatureReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {            
            SPWeb web = (SPWeb) properties.Feature.Parent;
            SPSecurity.RunWithElevatedPrivileges(delegate() {
                using (SPSite elevatedSite = new SPSite(web.Site.ID))
                {
                    using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
                    {
                        PageVariationReceiver.RegisterEventHandler(elevatedWeb);
                    }
                }
            });
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb)properties.Feature.Parent;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite elevatedSite = new SPSite(web.Site.ID))
                {
                    using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
                    {
                        PageVariationReceiver.UnregisterEventHandler(elevatedWeb);
                    }
                }
            });
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }
    }
}
